﻿Public Class WebForm1
    Inherits System.Web.UI.Page

    Dim sql As String
    Dim objDB As New DBConnect
    Dim ds As New DataSet

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        objDB = Session("db")
        Dim userID As String = Session("userID")



        If Not IsPostBack Then
            sql = "SELECT * FROM Game"
            ds = objDB.getDataSet(sql)
            ddlGameType.DataSource = ds
            ddlGameType.DataTextField = "GameName"
            ddlGameType.DataValueField = "GameID"
            ddlGameType.DataBind()

            Dim newSQL As String = "SELECT * FROM Match"
            ds = objDB.getDataSet(newSQL)

            gvMatches.DataSource = ds
            gvMatches.DataBind()

            
        End If



    End Sub

    Protected Sub ddlGameType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlGameType.SelectedIndexChanged
        'Response.Redirect(PlaceHolder.aspx)
    End Sub

    Protected Sub gvMatches_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvMatches.SelectedIndexChanged

    End Sub

    Protected Sub btnJoin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnJoin.Click

        Dim matchNum As Integer

        'rdbJoinGame
        For i As Integer = 1 To 6
            Dim isChecked As RadioButton = CType(gvMatches.Rows(i).Cells(2).FindControl("rdbJoinGame"), RadioButton)
            matchNum = gvMatches.Rows(i).Cells(0).Text
            If isChecked.Checked Then
                Dim sqlString As String = "INSERT INTO Match_Player '" + matchNum + "', '" + Session("userID") + "'"
                objDB.doUpdate(sqlString)
            End If
        Next
    End Sub
End Class